<%@ page import="model.UserService" %>
<%@ page import="java.util.Map" %>
<%
    //根据用户名查找用户id
    UserService userService = new UserService();
    String username = (String) session.getAttribute("loginName");
    Map<String, String> map = userService.getIdByUsername(username);
    String id = map.get("id");

    if (id != null) {
//    if(true) {
        //表示用户已登录
        // 根据id获取该用户信息
        Map<String, String> u = new UserService().getUserById(id);

%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!-- Modal -->

<div class="modal fade" id="user_edit_info" tabindex="-1" role="dialog"
     aria-hidden="true">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title text-info">修改用户信息</h5>
                <button type="button" class="close" data-dismiss="modal"
                        aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <form method="post" action="<%=request.getContextPath() %>/user_edit_infos.action">
                <input type="hidden" name="id" value="<%=u.get("id")%>"><br>
                <div class="modal-body">
                    <div class="form-group row">
                        <label class="col-sm-2 col-form-label">用户名</label>
                        <div class="col-sm-10">
                            <input class="form-control" id="username" value="<%=u.get("username")%>" name="un"
                                   type="text"
                                   required/> <span class="text-danger" id="checkInfo"></span>
                        </div>

                    </div>
                    <div class="form-group row">
                        <label class="col-sm-2 col-form-label">密码</label>
                        <div class="col-sm-10">
                            <input class="form-control" name="pw" type="password" required/>
                        </div>
                    </div>
                    <div class="form-group row">
                        <label class="col-sm-2 col-form-label">电话</label>
                        <div class="col-sm-10">
                            <input class="form-control" value="<%=u.get("telephone")%>" name="tel" type="number"
                                   required/>
                        </div>
                    </div>
                    <div class="form-group row">
                        <label class="col-sm-2 col-form-label">地址</label>
                        <div class="col-sm-10">
                            <input class="form-control" value="<%=u.get("address")%>" name="addr" type="text" required/>
                        </div>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary"
                            data-dismiss="modal">关闭
                    </button>
                    <button type="submit" class="btn btn-primary">确定</button>
                </div>
            </form>
        </div>
    </div>
</div>
<%
    }
%>